<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>

    <script src="./react/react.development.js"></script>
    <script src="./react/react-dom.development.js"></script>
    <script src="./react/babel.min.js"></script>
    <script src="./react/prop-types.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">

    //JSX=JS+xml、
    let app = document.querySelector('#app');
    let root = ReactDOM.createRoot(app);

    //继承类React.PureComponent ，或手动shouldComponentUpdate
    class Welcome extends React.PureComponent{
        state={
            msg:'hello',
            count:0,
            list:['a','v','c']
        }

        //list增加
        handleClick2 = () =>{
            this.setState((state)=>({count:0}))
            this.setState({
                list:[...this.state.list, 'd']
            })
        }

        render(){
            console.log('render')
            return(
                <div>
                    <button onClick={this.handleClick2}>点击</button>
                    {this.state.msg},{this.state.count},
                    <ul>
                        {
                            this.state.list.map((v,i) => <li key={i}>{v}</li>)
                        }
                    </ul>
                </div>
            )
        }
    }

    let info = {
        msg: 'hi react',
        username: 'lwj',
        age : '20'
    }

    let element = (<Welcome msg = "hi react class"/>)
    element = (<Welcome />)

    root.render(element);

</script>
</body>
</html>